function ajax(sourcesOption){
    const targetOption = {
        url:'',
        method:'get',
        data:{},
        headers:{
            "Content-Type":"appplication/x-www-form-urlencoded"
        },
        success:function(){
            
        },
        error:function(){
            
        }
    }
    Object.assign(targetOption.headers,sourcesOption.headers)
    Object.assign(targetOption,sourcesOption)
    let xhr = new XMLHttpRequest()
    let params = ''
    // xhr.responseType = 'json'
    if(targetOption.params){
        for(let item in targetOption.params){
        params += item + "=" + targetOption.params[item] + "&"
        } 
        params = params.substring(0,params.length - 1)
    }
    if(targetOption.data){
        params = ''
        for(let item in targetOption.data){
        params += item + "=" + targetOption.data[item] + "&"
        } 
        params = params.substring(0,params.length - 1)
    }
    switch(targetOption.method){
        case 'get' :
                    targetOption.url = targetOption.url + "?" + params
                    xhr.open(targetOption.method,targetOption.url)
                    xhr.send()
                    break
        case 'post' :
                    xhr.open(targetOption.method,targetOption.url)
                    let contentType = targetOption.headers["Content-Type"]
                    for(let item in targetOption.headers){
                        xhr.setRequestHeader(item,targetOption.headers[item])
                    }
                    if(contentType === "application/json"){
                        xhr.send(JSON.stringify(targetOption.data))
                    }else{
                        xhr.send(params)
                    }
                    break   
    }
    xhr.onreadystatechange=function(){
        if(xhr.readyState === 4){
            let contentType = xhr.getResponseHeader('Content-Type')
            let responseText = xhr.responseText
            if(contentType.includes("application/json")){
                responseText = JSON.parse(responseText)
            }
            if(xhr.status >= 200 && xhr.status <= 300){
                targetOption.success(responseText,xhr)
            }else{
                targetOption.error(responseText,xhr)
            }
            
        }
    }
}